<?php $this->pageHeader('Endre rettigheter for ' . $this->escape($this->group['name'])); ?>

<p id="top_right_links">
    <a href="<?php echo $this->url(array('module' => 'admin' , 'controller' => 'group', 'action' => 'edit', 'id' => $this->group['id'])) ?>" class="button"><img src="<?php echo $this->imageLink('images/icons/pencil.png'); ?>" />Rediger brukergruppe</a>
</p>

<?php
    if($this->successfulUpdate == true) {
        echo $this->flashMessage()->renderMessage('Oppdatering utført', RedCross_View_Helper_FlashMessage::SUCCESS);
    }
?>

<?php
    $form = $this->form;
    $form->setAction($this->url());
?>

<p>Du har valgt å endre rettighetene til gruppen <?php echo $this->escape($this->group['name']); ?>.<br />
I listen under finner du alle rettighetene som finnes i systemet:</p>
<p>&nbsp;</p>
<form method="<?php echo $form->getMethod(); ?>" action="<?php echo $form->getAction(); ?>">
    <table id="privileges">
        <thead>
            <tr>
                <th id="first">Ressurs</th>
                <th>Privilegier</th>
            </tr>
        </thead>
        <tbody>
        <?php
            foreach ($form->getElements() as $element) :
                if ($element instanceof Zend_Form_Element_Submit) {
                    $submit = $element;
                    continue;
                }
        ?>
            <tr>
                <td>
                <?php
                    if ($element->getDecorator('Description')) {
                        echo $element->renderDescription();
                    }
                ?>
                </td>
                <td>
                    <?php echo $element->renderViewHelper(); ?>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <p>&nbsp;</p>
    <p><?php echo $submit->renderViewHelper(); ?></p> 
</form>
<br />

<h2>Beskrivelser av de forskjellige rettighetene</h2>
<table>
    <?php foreach($this->resources as $resource) : ?>
        <tr>
            <th colspan="2">
                <?php
                    $nameArray =split(':', $resource->name);
                    $secondNameArray = split('[.]', $nameArray[1]);
                    $name = $nameArray[0];
                    $name = ucfirst($name);
                    if(isset($secondNameArray[1])) {
                        $module = $secondNameArray[0];
                        $module = ucfirst($module);
                        $controller = $secondNameArray[1];
                        $controller = ucfirst($controller);
                        $output = $name . ': ' . $module . ' - ' . $controller;
                    } else {
                        $service = $nameArray[1];
                        $service = ucfirst($service);
                        $output = $name . ': ' . $service;
                    }
                    echo $output;
                ?>
            </th>
        </tr>
        <?php foreach ($this->privileges as $privilege) : ?>
            <?php if($privilege->resource_id === $resource->id) : ?>
                <tr>
                    <td><?php echo $this->escape(ucfirst($privilege->name)); ?></td>
                    <td><?php echo $this->escape($privilege->description); ?></td>
                </tr>
            <?php endif;?>
        <?php endforeach; ?>
    <?php endforeach; ?>
</table>

